﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using TinyLib.Input;
using TinyLib.Sprite;
using TinyLib.Entity;

namespace GodBuilderIdea
{
    public class WorldEventBox : Entity
    {
        public String m_text = "";
        Sprite m_background;
        SpriteFont m_font;
        public bool m_active = false;
        public bool m_tool_tip = false;
        
        private List<IEvent> m_actionEvents = new List<IEvent>();
        public WorldEventBox(Game game, SpriteBatch sprite_batch, String p_text, bool tool_tip = false)
            : base(game, sprite_batch)
        {
            m_tool_tip = tool_tip;
            m_text = p_text;
            Initialize();
        }

        public void RegisterActionEvent(IEvent actionEvent)
        {
            m_actionEvents.Add(actionEvent);
        }

        private void DoActions()
        {
            foreach (IEvent actionEvent in m_actionEvents)
                actionEvent.Excecute();
        }

        public void ActivateEvent()
        {
            m_active = true;
            DoActions();
        }

        public override void Initialize()
        {
            Texture2D tex = Game.Content.Load<Texture2D>("images/world_evt_background");
            if (m_tool_tip) { tex = Game.Content.Load<Texture2D>("images/did_you_know_background"); }
            m_background = new Sprite(Spritebatch, tex, Game);
            m_background.position = new Vector2(400, 200);

            m_font = Game.Content.Load<SpriteFont>("Font");

            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            if (m_active)
            {
                m_background.Draw(gameTime);
                Spritebatch.DrawString(m_font, m_text, new Vector2(m_background.position.X + 60, m_background.position.Y + 150), Color.Black);
            }
            //base.Draw(gameTime);
        }
    }
}
